<template>
    <div class="user-menu-list">
        <a @click="toIndex" class="index user-menu-btn">
            <img class="icon" :src="img.indexIcon">
            <span class="text">主页</span>
        </a>
        <a @click="clickBus" :class="busStu.className" class="check-bus user-menu-btn">
            {{busStu.text}}
        </a>
    </div>
</template>

<script>
// 自定义方法
import { getProImg } from "_projectFn/images"
import { enterUserBus } from "_projectFn/page"
import { getCookie } from '_commonFn/cookie'
import { toIndex, enterUserAccSet, } from '_projectFn/page'

// 本地图片
import indexImg from "_assets/img/to-index-association.svg"

// 自定义组件
import ShowUserWechatInfo from "_components/project/common/ShowUserWechatInfo"

export default {
    name: 'UserMenu',
    props: {
        userInfo: {
            type: Object,
            default: {},
        }
    },
    data() {
        return {
            img: {
                indexIcon: getProImg('to-index-association.svg', indexImg),
            }
        }
    },
    methods: {
        toIndex() {
			toIndex({})
        },
        clickBus() {
            if (this.busStu.className === 'check') {
                this.clickUserBus()
            } else if (this.busStu.className === 'create') {
                enterUserAccSet('business')
            }
        },
        clickUserBus() {
            const that = this
            this.checkIsCan(() => {
                enterUserBus({
                    userId: that.$route.query.userId
                })
            })
        },
        clickUserWechat() {
            // console.log(this.userInfo.userId)
            const that = this
            this.checkIsCan(() => {
                that.$refs.showUserWechatInfo.checktWechatInfo()
            })
        },
        checkIsCan(callback) {
            if (this.userInfo.isUserBusiness) {
                typeof callback === 'function' && callback()
            }
        },
    },
    computed: {
        busStu() {
            const data = {
                text: '',
                className: ''
            }
            const isUserBusiness = this.userInfo.isUserBusiness
            if (isUserBusiness != null) {
                if (isUserBusiness) {
                    data.text = '查看业务名片'
                    data.className = 'check'
                } else if (isUserBusiness == 0) {
                    const myUserId = getCookie('UserId')
                    if (myUserId && myUserId == this.userInfo.userId) {
                        data.text = '创建业务名片'
                        data.className = 'create'
                    } else {
                        data.text = '尚无业务名片'
                        data.className = 'without'
                    }
                }
            }
            return data
        },
    },
    components: {
        ShowUserWechatInfo,
    }
}
</script>

<style lang="scss" scoped>
.user-menu-list {
    position: fixed;
    bottom: 0;
    height: 50px;
    width: 100%;
    display: flex;
    border-top: 1px solid #eeeeee;

    .user-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100%;
        flex-direction: column;
    }

    .index {
        width: 100px;
        flex-shrink: 0;
        color: #333333;
        font-size: 12px;

        .icon {
            width: 15px;
            height: 15px;
        }
        .text {
            height: 18px;
            margin-top: 3px;
        }
    }

    .check-bus {
        background: #0077bf;
        color: white;
        font-size: 16px;
        font-weight: bold;
        width: 100%;
    }
}
</style>